﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Popup_CharacterEffect : Popup_Base
{
    const float LineGapY = 100.0f;
    const float StartY = -20.0f;
    public GameObject m_ExplainingLine;

    public override void AwakeInit()
    {
        int numOfLine = UserData.Instance.userModel.m_PartySincSuccessList.Count;

        GameObject tempLine = null;
        UILabel nameLabel = null;
        UILabel BobyLabel = null;

        if (numOfLine > 0)
        {
            for (int i = 0; i < numOfLine; i++)
            {
                if (i == 0)
                {
                    tempLine = m_ExplainingLine;
                }
                else
                {
                    tempLine = Instantiate(m_ExplainingLine) as GameObject;
                    tempLine.transform.parent = m_ExplainingLine.transform.parent;
                    tempLine.transform.localScale = m_ExplainingLine.transform.localScale;
                    tempLine.transform.localRotation = m_ExplainingLine.transform.localRotation;
                }

                Vector3 pos = m_ExplainingLine.transform.localPosition;
                pos.y = (i * LineGapY) + StartY;
                tempLine.transform.localPosition = pos;

                Transform crossLine = tempLine.transform.FindChild("line");
                nameLabel = tempLine.transform.FindChild("effectname").GetComponent("UILabel") as UILabel;
                BobyLabel = tempLine.transform.FindChild("explaining").GetComponent("UILabel") as UILabel;

                nameLabel.text = TextController.GetStringWithId(string.Format("partySync{0}", UserData.Instance.userModel.m_PartySincSuccessList[i].syncID));                
                nameLabel.MakePixelPerfect();
                BobyLabel.text = TextController.GetStringWithId(string.Format("partySyncInfo{0}", UserData.Instance.userModel.m_PartySincSuccessList[i].syncID));                
                BobyLabel.MakePixelPerfect();
              
                float gap1 = 120.0f;
                float gap2 = 35.0f;
                float totalSize = nameLabel.localSize.x + BobyLabel.localSize.x + gap1 + gap2;
                float startSize = -(totalSize / 2);

                pos = nameLabel.transform.localPosition;
                pos.x = startSize;
                nameLabel.transform.localPosition = pos;


                pos = crossLine.localPosition;
                pos.x = nameLabel.transform.localPosition.x + nameLabel.localSize.x + gap1;
                crossLine.localPosition = pos;


                pos = BobyLabel.transform.localPosition;
                pos.x = crossLine.localPosition.x + gap2;
                BobyLabel.transform.localPosition = pos;
            }
        }
        else
        {
            m_ExplainingLine.SetActive(false);
        }
    }
    
    public override void ButtonTouch(Collider collider)  // 버튼 터치 (터치 시작 끝 같은 오브젝트일때 터치 끝 시점에 호출)
    {
        if(collider.name == "Button_OK")
        {
            BackButton();
        }
    }

    public override void BackButton()
    {
        PopupManager.PopPopup();
    }
}